<?
if(!isset($_REQUEST['bid'])){
    die("Create one or more blocks");
}
function section_theme($data, $params, $href = "") {
    $str = "";
    foreach ($data as $i => $section) {
        $str .= "<li>";
        $str .= "<a href=\"$href&sid=" . $section['id'] . "&action=show_section\">" . $section['title'] . "</a>";
        $str .= "<a class=\"iframe-fancy button\" href=\"/admin/actions/elements.php?id=" . $section['id'] . "&action=show_element\">Edit section</a>";
        $str .= "<a class=\"iframe-fancy button\" href=\"/admin/actions/elements.php?id=" . $section['id'] . "&action=delete_element\">Delete section</a>";
        if (!empty($section["sections"])) {
            $str .= section_theme($section['sections'], $params, $href);
        }
        $str .= "</li>";
    }
    return "<ul>" . $str . "</ul>";
}

print "<a href=\"?bid=" . $params['block_id'] . "\">Block elements</a>";
print section_theme($result, $params, "?bid=" . $params['block_id']);

if (isset($_REQUEST['sid'])) {
    $filter = array('section_id' => $_REQUEST['sid'], 'type' => 'E');
} else {
    $filter = array('block_id' => $_REQUEST['bid'], 'type' => 'E');
}
$elements = BDSElements::GetList($filter);

?>
<div class="plates">
    <ul><li>
            <div class="container type">
                <a href="/admin/actions/elements.php?action=new_element&block_id=<?=$_REQUEST['bid']?>&section_id=<?=(isset($_REQUEST['sid']) ? $_REQUEST['sid'] : 0)?>" class="iframe-fancy button">new Element</a>
                <a href="/admin/actions/elements.php?action=new_section&block_id=<?=$_REQUEST['bid']?>&section_id=<?=(isset($_REQUEST['sid']) ? $_REQUEST['sid'] : 0)?>" class="iframe-fancy button">new Section</a>                
            </div>
        </li>
<? foreach ($elements as $element): ?><li>
    <div class="container block">
        <div class="item-title"><?=$element['title']?></div>
        <a href="/admin/actions/elements.php?action=show_element&id=<?=$element['id']?>" class="iframe-fancy button">Edit Element</a>
        <a href="/admin/actions/elements.php?action=delete_element&id=<?=$element['id']?>" class="iframe-fancy button">Delete Element</a>
    </div>
</li><? endforeach;?>
    </ul>
</div>
